/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#ifndef SNAPSHOT_TREE_MODEL_H
#define SNAPSHOT_TREE_MODEL_H

#include <QtCore/QSortFilterProxyModel>

class SnapshotTree;
class SnapshotNode;

class SnapshotTreeModel : public QAbstractItemModel {
	Q_OBJECT
public:
	SnapshotTreeModel();
	virtual ~SnapshotTreeModel();

	void	setTree( SnapshotTree *tree );

	virtual QModelIndex	index( int row, int column, const QModelIndex &parent = QModelIndex() ) const;
	virtual QModelIndex	parent( const QModelIndex &index ) const;
	virtual int			rowCount( const QModelIndex &parent = QModelIndex() ) const;
	virtual int			columnCount( const QModelIndex & parent = QModelIndex() ) const;
	virtual QVariant	data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
	virtual QVariant	headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

private slots:

	void	rootAdded();
	void	rootsCleared();
	void	updateCoverage();

private:

	void	updateCoverage( SnapshotNode *node );

	SnapshotTree	*m_tree;
};

class SnapshotTreeProxyModel : public QSortFilterProxyModel {
	Q_OBJECT
public:
	SnapshotTreeProxyModel();
	virtual ~SnapshotTreeProxyModel();

	void	setTree( SnapshotTree *tree );

protected:

	virtual bool	filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;

private slots:

	void	updateVisibility();

private:

	SnapshotTreeModel	*m_sourceModel;
	SnapshotTree		*m_tree;
};

#endif // SNAPSHOT_TREE_MODEL_H